/*package com.good.controller;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.octo.captcha.service.multitype.GenericManageableCaptchaService;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

@SuppressWarnings("restriction")
@Controller
public class CodeController {
	@Autowired
	private GenericManageableCaptchaService captchaService;

	@RequestMapping(value = "/getcode", method = RequestMethod.GET)
	public void getCode(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) {

		byte[] captchaChallengeAsJpeg = null;
		// 输出jpg的字节流
		ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
		try {
			String captchaId = httpServletRequest.getSession().getId();
			BufferedImage challenge = (BufferedImage) captchaService
					.getChallengeForID(captchaId,
							httpServletRequest.getLocale());
			// a jpeg encoder
			JPEGImageEncoder jpegEncoder = JPEGCodec
					.createJPEGEncoder(jpegOutputStream);
			jpegEncoder.encode(challenge);
			captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
			httpServletResponse.setHeader("Cache-Control", "no-store");
			httpServletResponse.setHeader("Pragma", "no-cache");
			httpServletResponse.setDateHeader("Expires", 0);
			httpServletResponse.setContentType("image/jpeg");
			ServletOutputStream responseOutputStream = httpServletResponse
					.getOutputStream();
			responseOutputStream.write(captchaChallengeAsJpeg);
			responseOutputStream.flush();
			responseOutputStream.close();
		} catch (Exception e) {
			try {
				httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return;
		}

	}
	@RequestMapping(value="check",method=RequestMethod.GET)
	public String check(HttpServletRequest request){
		Boolean isCorrect = Boolean.FALSE;
		String captchaId = request.getSession().getId();
		String code = request.getParameter("code");
		try {
		  isCorrect = captchaService.validateResponseForID(captchaId,
		      code);
		  if (!isCorrect) {
		    return "usr/tologin";
		  }
		} catch (Exception e) {
		}
		return "";
	}
}
*/